%% this code aims to average the adata of n trials.
%% set parameter.
m = 8;%% muscle number;
t = 10;%% each block contains t trials;
s = 1;%% starting trial;
e = 10;%% ending trial;
block_name =1;%% the name of saved data;
    %% extract the data;
for j = 1:m
    for i = s:e
    filename = sprintf('/Users/chenzhi/cz.ongoing/AOP_conference/aligned_data/%d_aligned_data.csv',i);
    raw_data = importdata(filename)
    sub_data(:,i) = raw_data(:,j);
    all_data(:,j) = mean(sub_data,2);
    end
end
save_filename = sprintf('/Users/chenzhi/cz.ongoing/AOP_conference/block_average/%d_average_data',block_name);
xlswrite(save_filename,all_data);

